home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / pbbs / src60.arc / MB.C < prev    next >
Text File  |  1989-01-26  |  8KB  |  409 lines

  1. /*
  2.  *  MB.C - 1/24/89 - MailBox mainline code.
  3.  */
  4.  
  5. /*
  6.  *  Copyright (C) 1987, 1988
  7.  *  On Modules by H. N. Oredson
  8.  *  Copyright (C) 1988, 1989
  9.  *  By the CBBS Group.
  10.  *
  11.  *  This code was originality created and distributed
  12.  *  to the packet radio community by W0RLI and VE3GYQ.
  13.  *  It is being further being developed by the CBBS Group.
  14.  *  It may be freely copied for non-commercial use,
  15.  *  as long as this notice is retained.
  16.  *
  17.  *  This notice and Copyright apply to all modules
  18.  *  referenced by this module.
  19.  *
  20.  */
  21.  
  22. #include "mb.h"
  23.  
  24. char  *ver = "\nC-BBS V6.0, 15 Jan 1989\n";
  25.  
  26. char  *nullstr = "";
  27.  
  28. PORTS *porthd = NULL;
  29. PORTS *cport  = NULL;
  30. PORTS *port;
  31.  
  32. int   scrmax, dirmax;
  33. TMP   *tmp;
  34. MLM   *motd;
  35. char  *helpfile, *infofile;
  36. char  *bbmenu, *symenu, *rmenus, *mumsg;
  37. char  *reqmsg, *qth, *keylst;
  38. char  *mcant, *mdone, *mfind, *mexst, *mnfile, *mnmsg;
  39. char  *mprot, *mtime, *mwhat, *mnport, *mndir, *minuse;
  40. char  achar, rchar, tchar, wchar;
  41. word  s_param;
  42. byte  s_flag, unt_hr, window, c_flag, b_flag;
  43. char  scmd[24];
  44.  
  45. main(argc, argv)
  46. int argc;
  47. char *argv[];
  48. {
  49.   if (argc > 1) init(argv[1]); else init("config.mb");
  50.  
  51.   while (true)
  52.   {
  53.     bidok = false;
  54.     hidok = false;
  55.     do_idle();
  56.     setbusy();
  57.     login();
  58.     if (!(port->mode & exclude)) do_cmds();
  59.     logo();
  60.   }
  61. }
  62.  
  63. do_cmds()
  64. {
  65.   register PORTS *p;
  66.   register char  *i, *o;
  67.  
  68.   p = port;
  69.  
  70.   while(true)
  71.   {
  72.     prompt();
  73.     getcmd();
  74.     if (p->mode & gone) return;
  75.  
  76. /*
  77.  *  Console broke in on a user?
  78.  */
  79.  
  80.     if (p->flags & p_opreq)
  81.     {
  82.       p->flags clrbit p_opreq;
  83.       prtx(talkm1);
  84.       if (p->tmode)
  85.       {
  86.          cmdtnc();
  87.          convtnc();
  88.       }
  89.       ioport(cport);
  90.       prtx(mumsg);
  91.       cport->fl = NULL;
  92.       term(p);
  93.       ioport(p);
  94.       tncstate();
  95.       if (p->tmode) trantnc(); else convtnc();
  96.       if (p->mode & gone) return;
  97.     }
  98.  
  99. /*
  100.  *  Check for LINK.
  101.  *  Require "LINKED to" to be first command.
  102.  */
  103.  
  104.     else if (islink(p->line))
  105.     {
  106.       if (p->cmdcnt) p->msg = mwhat; else
  107.       {
  108.         strcpy(p->line, p->line + 14);
  109.         logina(true);
  110.         remnl(p->line);
  111.         log('C', 'L', ' ', p->line);
  112.         if (p->mode & exclude) return;
  113.       }
  114.     }
  115.  
  116. /*
  117.  *  Must be a command.
  118.  */
  119.  
  120.     else
  121.     {
  122.       docmd();
  123.       if (p->errors > p->errmax) p->mode = forced;
  124.       if (p->mode & (gone | idle | logout)) return;
  125.     }
  126.   }
  127. }
  128.  
  129. /*
  130.  *  Q command: exit to DOS.
  131.  */
  132.  
  133. done()
  134. {
  135.   byte pflg;
  136.  
  137.   if (sure()) return;
  138.   upduser(cport->user);
  139.   log('X', 'Q', ' ', nullstr);
  140.   clslog();
  141.   clsusr();
  142.   clsmsg();
  143.   clsmon();
  144.   iooff();
  145.   clrbusy();
  146.   pflg = getp_flag();
  147.   putp_flag(pflg clrbit window);
  148.   exit(0);
  149. }
  150.  
  151. /*
  152.  *  Give the user a prompt.
  153.  */
  154.  
  155. prompt()
  156. {
  157.   register PORTS *p, *tp;
  158.  
  159.   p = port;
  160.   if (p->msg isnt NULL) prtx(p->msg);
  161.   p->msg = NULL;
  162.  
  163. /*
  164.  *  Tell sysop who this is.
  165.  */
  166.  
  167.   if (p isnt cport) { ioport(cport); prtx(mumsg); ioport(p); }
  168.  
  169. /*
  170.  *  Show any connect request seen on the user port.
  171.  */
  172.  
  173.   if (p->flags & p_req) prtx(reqmsg);
  174.   p->flags clrbit p_req;
  175.  
  176. /*
  177.  *  Bleed off any connect requests on other ports.
  178.  */
  179.  
  180.   for (tp = porthd; tp isnt NULL; tp = tp->next) if (tp->mode & idle)
  181.   if ((tp->dev is p_tnc) and (tp isnt p))
  182.   {
  183.     ioport(tp);
  184.     while (instat()) getdat();
  185.   }
  186.   ioport(p);
  187.  
  188. /*
  189.  *  Display the prompt.
  190.  */
  191.  
  192.   curtim();
  193.   switch (p->mode)
  194.   {
  195.     case local :
  196.     case sysop :
  197.       prtx(symenu);
  198.       break;
  199.  
  200.     case remote:
  201.       if (!(p->user->options & u_bbs))
  202.       {
  203.         if (s_param & s_p_name) if (!(p->user->state & u_name)) prtx(um[4]);
  204.         if (s_param & s_p_home) if (!(p->user->state & u_home)) prtx(um[5]);
  205.         if (s_param & s_p_zip)  if (!(p->user->state & u_zip))  prtx(um[6]);
  206.       }
  207.  
  208.       if (p->user->options & (u_bbs | u_expert)) prtx(bbmenu); else prtx(rmenus);
  209.       break;
  210.   }
  211. }
  212.  
  213. /*
  214.  *  Log the user off.
  215.  *  Do any defered remote sysop command.
  216.  */
  217.  
  218. logo()
  219. {
  220.   register PORTS *p;
  221.   register PORTS *tp;
  222.   register char t;
  223.  
  224.   p = port;
  225.  
  226.   switch(p->mode)
  227.   {
  228.     case idle   : t = 'A'; break; /* Init bbs logout */
  229.     case logout : t = 'B'; break;
  230.     case discon : t = 'D'; break;
  231.     case exclude: t = 'E'; break;
  232.     case forced : t = 'F'; distnc(); break;
  233.     case timeout: t = 'T'; prtx(mtime); break;
  234.     default     : t = '?'; break;
  235.   }
  236.  
  237.   log('X', t, ' ', nullstr);
  238.  
  239. /*
  240.  *  If any port was used in terminal mode by the console,
  241.  *  disconnect it.
  242.  */
  243.  
  244.   if (p->dev is p_console)
  245.   for (tp = porthd; tp isnt NULL; tp = tp->next)
  246.   if (tp->flags & p_term)
  247.   {
  248.     ioport(tp);
  249.     tp->mode = remote;
  250.     distnc();
  251.     tp->mode = idle;
  252.     tp->flags clrbit p_term;
  253.   }
  254.  
  255.   ioport(p);
  256.  
  257. /*
  258.  *  Change TNC back to "standard" if was in "sysop" mode.
  259.  *  May have just THOUGHT we discon, REALLY disconnect.
  260.  */
  261.  
  262.   if (p->dev is p_tnc)
  263.   {
  264.     if (p->flags & p_clrsys) mkrem();
  265.     p->mode = remote;
  266.     distnc();
  267.   }
  268.   if (p->dev is p_serial) p->flags clrbit p_trans;
  269.   p->mode = idle;
  270.  
  271.   upduser(p->user);
  272.  
  273. /*
  274.  *  If there was a "defered remote sysop command" do it.
  275.  */
  276.  
  277.   ioport(cport);
  278.   if (s_param & s_cmd)
  279.   {
  280.     s_param clrbit s_cmd;
  281.     strcpy(cport->line, scmd);
  282.     parse();
  283.     wait(10);               /* Give sysop chance to get HIS system online */
  284.     cport->mode = local;    /* Do command as if console did it */
  285.     docmd();
  286.     cport->mode = idle;
  287.   }
  288.  
  289.   clnlog();
  290.   clsusr();
  291.   setfwd();
  292.   clsmsg();
  293. }
  294.  
  295. /*
  296.  *  MailBox is idle.
  297.  *  See if there is anything to do, and do it.
  298.  *  If nothing to do, wait for connect.
  299.  */
  300.  
  301. do_idle()
  302. {
  303.   register PORTS *p;
  304.   register short curmin, lastmin;
  305.  
  306.   for (p = porthd; p isnt NULL; p = p->next) p->ec = p->ecmon;
  307.  
  308.   getc_flag();
  309.   if (c_flag & window) acmd();
  310.  
  311.   allon();  /* Turn on monitoring and connects */
  312.   clrbusy();
  313.   curtim();
  314.   curmin = 10 * (l_time[2] - '0') + (l_time[3] - '0');
  315.   while(true)
  316.   {
  317.  
  318. /*
  319.  *  Check the port command flag to see if another window has
  320.  *  issued a command request. If so setup and do the command.
  321.  */
  322.  
  323.     getc_flag();
  324.     if (c_flag & window)
  325.     {
  326.       setbusy();
  327.       alloff();
  328.       acmd();
  329.       allon();
  330.       clrbusy();
  331.     }
  332.  
  333.     lastmin = curmin;
  334.     curtim();
  335.     curmin = 10 * (l_time[2] - '0') + (l_time[3] - '0');
  336.  
  337. /*
  338.  *  Once each minute:
  339.  *  Forward now, if it is time on any port.
  340.  */
  341.  
  342.     if (curmin isnt lastmin) afwd(curmin);
  343.  
  344. /*
  345.  *  Look for a login.
  346.  */
  347.  
  348.     for (p = porthd; p isnt NULL; p = p->next)
  349.     {
  350.       ioport(p);
  351.       if (instat()) switch(p->dev)
  352.       {
  353.         case p_serial:
  354.           p->flags clrbit p_give;
  355.           getdat();
  356.           p->flags setbit p_give;
  357.           if (iscon(p->line)) return;
  358.           break;
  359.  
  360.         case p_tnc:
  361.           p->flags clrbit p_give;
  362.           getdat();
  363.           p->flags setbit p_give;
  364.           if (iscon(p->line)) return;
  365.           monitor();
  366.           break;
  367.  
  368.         case p_console:
  369.           if (inchar() is wchar) return;
  370.           break;
  371.       }
  372.       p->flags setbit p_give;
  373.     }
  374.   }
  375. }
  376.  
  377. /*
  378.  *  Do commands retrieved from the bios.
  379.  */
  380.  
  381. acmd()
  382. {
  383.    char need_msg = false;
  384.  
  385.    port->mode = local;
  386.    getcomd();
  387.    if (s_flag & s_dv) begin_lock();
  388.    if (port->opt1 is 'X')
  389.    {
  390.      readmsg();
  391.      readusr();
  392.      need_msg = true;
  393.    }
  394.    getc_flag();
  395.    putc_flag( c_flag clrbit window);
  396.    if (s_flag & s_dv) end_lock();
  397.    sprintf(port->line, "%c%c", port->opt1, port->opt2);
  398.    parse();
  399.    docmd();
  400.    if (need_msg)
  401.    {
  402.      clnlog();
  403.      setfwd();
  404.      clsmsg();
  405.      clsusr();
  406.    }
  407.    port->mode = idle;
  408. }
  409.